package giaodien;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import java.awt.Color;

import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.ImageIcon;
import javax.swing.JButton;

import model.MatHang;
import controller.MatHangController;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class XoaSanPham extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					XoaSanPham frame = new XoaSanPham(0);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public XoaSanPham(final int id) {
		setTitle("Xóa sản phẩm");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 437, 208);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLabel lblBnCMun = new JLabel("Bạn có muốn xóa sản phẩm này không?");
		lblBnCMun.setForeground(new Color(255, 0, 0));
		lblBnCMun.setFont(new Font("Tahoma", Font.BOLD, 13));
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon(XoaSanPham.class.getResource("/icon/xoa.png")));
		
		JButton btnng = new JButton("Đồng ý");
		btnng.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
				MatHangController.deleteMatHang(id);
				JOptionPane.showMessageDialog(null,
						"Xóa sản phẩm thành công");
			}
		});
		btnng.setForeground(new Color(139, 0, 0));
		btnng.setFont(new Font("Tahoma", Font.BOLD, 13));
		
		JButton btnHyB = new JButton("Hủy bỏ");
		btnHyB.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		btnHyB.setForeground(new Color(139, 0, 0));
		btnHyB.setFont(new Font("Tahoma", Font.BOLD, 13));
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
							.addGap(15)
							.addComponent(lblBnCMun))
						.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
							.addGap(43)
							.addComponent(btnng)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(btnHyB)))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(label, GroupLayout.PREFERRED_SIZE, 123, Short.MAX_VALUE)
					.addContainerGap())
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addComponent(label))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(23)
							.addComponent(lblBnCMun)
							.addGap(37)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(btnng, Alignment.TRAILING)
								.addComponent(btnHyB, Alignment.TRAILING))))
					.addContainerGap(21, Short.MAX_VALUE))
		);
		contentPane.setLayout(gl_contentPane);
	}

}
